package cn.net.shuxing.yifu.common.service;

import cn.net.shuxing.yifu.common.bean.Permission;
import cn.net.shuxing.yifu.common.bean.PermissionGroup;
import cn.net.shuxing.yifu.common.mapper.PermissionGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PermissionGroupService extends BaseService<PermissionGroup,PermissionGroupMapper> {

    @Autowired
    private PermissionService permissionService;

    public PermissionGroupService insertPermissionGroup(String groupName)
    {
        PermissionGroup permissionGroup = new PermissionGroup();
        permissionGroup.setName(groupName);

        mapper.insertSelective(permissionGroup);
        return this;
    }

    @Override
    protected void complete(PermissionGroup permissionGroup)
    {
        if (permissionGroup == null)
            return;
        Permission permission = new Permission();
        permission.clearCreateTimeAndUpdateTime();
        permission.setPermissionGroupId(permissionGroup.getId());

        permissionGroup.setPermissionList(permissionService.gets(permission));
    }
}
